package cn.paxos.mysql.h2enginee;

import cn.paxos.mysql.ResultSetWriter;
import cn.paxos.mysql.engine.SqlEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;

/**
 * H2database实现的引擎
 */
@Service
public class H2SqlEngineeImpl implements SqlEngine {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 返回版本号
     *
     * @return
     */
    @Override
    public String getVersion() {
        return "5.7.0-h2";
    }

    /**
     * Authenticating the user and password.
     *
     * @param database    Database name
     * @param userName    User name
     * @param scramble411 Encoded password
     * @param authSeed    Encoding seed
     * @throws IOException Thrown with IllegalAccessException as the inner cause if the authentication is failed
     */
    @Override
    public void authenticate(String database, String userName, byte[] scramble411, byte[] authSeed) throws IOException {
        
    }

    /**
     * Querying the SQL.
     *
     * @param resultSetWriter Response writer
     * @param database        Database name
     * @param userName        User name
     * @param scramble411     Encoded password
     * @param authSeed        Encoding seed
     * @param sql             SQL text
     * @throws IOException Thrown with IllegalAccessException as the inner cause if the authentication/authorization is failed, or IllegalArgumentException if SQL is invalid
     */
    @Override
    public void query(ResultSetWriter resultSetWriter, String database, String userName, byte[] scramble411, byte[] authSeed, String sql) throws IOException {
        //Map<String, Object> stringObjectMap = jdbcTemplate.queryForMap(sql);
    }
}
